package org.davidliebman.android.awesomecube;

import java.util.ArrayList;

public class MeshPart {
	
	public ArrayList<PointXYZ> mPoints = new ArrayList<PointXYZ>();
	public ArrayList<IndexCombo> mIndex = new ArrayList<IndexCombo>();
	
	public static final int SHAPE_SQUARE = 0;
	public static final int SHAPE_OBLONG_A = 1;
	public static final int SHAPE_OBLONG_B = 2;
	public static final int SHAPE_MIRROR = 3;
	
	public float mDistanceLeft = 0.5f;
	public float mDistanceRight = 0.5f;
	public float mDistanceTop = 0.5f;
	public float mDistanceBot = 0.5f;
	public float mDistanceCenter = 0.5f;
	
	public int mShape = SHAPE_SQUARE;
	
	public int mTextureNum = 0;
	public boolean mReverseWinding = false;
	public float mDimension = 1;
	public float mHalfDimension = mDimension / 2;
	
	public MeshPart () {
		
	}
	
	public MeshPart (PointXYZ p) {
		mPoints.clear();
		mPoints.add(p);
	}
	
	public MeshPart (PointXYZ p, float tx, float ty) {
		p.mTextureX = tx;
		p.mTextureY = ty;
		
		mPoints.clear();
		mPoints.add(p);
	}
	
	public MeshPart (int textureID) {
		
		this.mTextureNum = textureID;
		
	}
	
	public void setDistanceVars() {
		switch ( mShape ) {
		case SHAPE_SQUARE :
			mDistanceLeft = 0.5f;
			mDistanceRight = 0.5f;
			mDistanceTop = 0.5f;
			mDistanceBot = 0.5f;
			mDistanceCenter = 0.5f;
			break;
		case SHAPE_OBLONG_A :
			mDistanceLeft = 1.5f;
			mDistanceRight = 1.5f;
			mDistanceTop = 0.5f;
			mDistanceBot = 0.5f;
			mDistanceCenter = 0.5f;
			break;
		case SHAPE_OBLONG_B :
			mDistanceLeft = 0.5f;
			mDistanceRight = 0.5f;
			mDistanceTop = 1.5f;
			mDistanceBot = 1.5f;
			mDistanceCenter = 0.5f;
			break;
		case SHAPE_MIRROR :
			//mDistanceLeft = 0.5f;
			//mDistanceRight = 0.5f;
			//mDistanceTop = 0.5f;
			//mDistanceBot = 0.5f;
			break;
		}
		
	}
	
	public void add(PointXYZ p, float tx, float ty) {
		p.mTextureX = tx;
		p.mTextureY = ty;
		
		mPoints.add(p);
	}
	
	public void addVertex(PointXYZ p) {
		mPoints.add(p);
	}
	
	public PointXYZ getVertex(int i) {
		return mPoints.get(i);
	}
	
	public void addIndex (short i) {
		mIndex.add(new IndexCombo(i));
	}
	
	public short getIndex (int i) {
		
		int j = this.mIndex.size() - 1;
		int k = i;
		if (mReverseWinding) {
			k = j - i;
		}
		
		return (short)mIndex.get(k).getIndex();
	}
	
	public void setShape(int mShape ) {
		this.mShape = mShape;
	}
	public int getShape() {
		return mShape;
	}
}

class PointXYZ {
	public float x, y, z;

	public float mModX, mModY, mModZ;
	
	public float mTextureX, mTextureY;
	
	public PointXYZ (float x, float y , float z) {
		this.x = x;
		this.y = y;
		this.z = z;
		
		mModX = 0; // change angle measurement...
		mModY = 0;
		mModZ = 0;
		
		mTextureX = 0;
		mTextureY = 0;
	}
	
	public PointXYZ (float x, float y , float z, float tx, float ty) {
		this.x = x;
		this.y = y;
		this.z = z;
		
		mModX = 0; // change angle measurement...
		mModY = 0;
		mModZ = 0;
		
		mTextureX = tx;
		mTextureY = ty;
	}
	
	public void set(float x, float y, float z) {
		this.x = x;
		this.y = y;
		this.z = z;
		
	}
	
	public float getX() {
		return x;
	}

	public void setX(float x) {
		this.x = x;
	}

	public float getY() {
		return y;
	}

	public void setY(float y) {
		this.y = y;
	}

	public float getZ() {
		return z;
	}

	public void setZ(float z) {
		this.z = z;
	}

	public float getModX() {
		return mModX;
	}

	public void setModX(float mModX) {
		this.mModX = mModX;
	}

	public float getModY() {
		return mModY;
	}

	public void setModY(float mModY) {
		this.mModY = mModY;
	}

	public float getModZ() {
		return mModZ;
	}

	public void setModZ(float mModZ) {
		this.mModZ = mModZ;
	}

	public float getTextureX() {
		return mTextureX;
	}

	public void setTextureX(float mTextureX) {
		this.mTextureX = mTextureX;
	}

	public float getTextureY() {
		return mTextureY;
	}

	public void setTextureY(float mTextureY) {
		this.mTextureY = mTextureY;
	}
	
	public void setTextureXY(float tx, float ty) {
		this.mTextureX = tx;
		this.mTextureY = ty;
	}
}

class IndexCombo {
	public short mIndex;
	
	public IndexCombo(short i) {
		this.mIndex = i;
	}
	
	public int getIndex() {
		return mIndex;
	}
	public void setIndex(short mIndex) {
		this.mIndex = mIndex;
	}
	
	
	
}